/* a simple test */
#include "cstring.h"

static const char* eg =
    "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";

static inline cstring foo(cstring t)
{
    cstring_make_literal(hello, "hello");
    cstring_make_buffer(ret);
    if (cstring_equal(hello, t)) {
        cstring_cat(ret, "equal");
    }
    else {
        cstring_cat(ret, "not equal");
    }
    return cstring_grab(ret->data);
}

static inline void test1()
{
    cstring_make_buffer(a);
    cstring_vprintf(a, "%s", "hello");
    cstring b = foo(a->data);
    printf("%s: %s\n", b->cstr, a->data->cstr);
    cstring_vprintf(a, "long string: %s", eg);
    printf("%s\n", a->data->cstr);
    cstring_close(a);
    cstring_release(b);
}

static inline void test2()
{
    int i = 0;
    for (i = 1; i <= 5000000; ++i) {
        if (!(i % 1000000)) {
            printf("%d\n", i);
        }
        cstring_make_buffer(a);
        cstring_vprintf(a, "%s", "hello");
        cstring b = foo(a->data);
        cstring_vprintf(a, "long string: %s", eg);
        cstring_close(a);
        cstring_release(b);
    }
}

int main(int argc, char* argv[], char* env[])
{
    test1();
    test2();
    printf("test OK\n");
    return 0;
}

